home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: FileIconPane.cp
-
- Contains: Implementation of a simple pane that draws the icon
- associated with a file (specified as either an IconRef
- or a color icon ID).
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- // ===========================================================================
- // FileIconPane.cp
- // ===========================================================================
-
- #pragma once
-
- #include "FileIconPane.h"
-
- #include <Icons.h>
-
-
- // ---------------------------------------------------------------------------
- // • FileIconPane Stream Constructor [public]
- // ---------------------------------------------------------------------------
-
- FileIconPane::FileIconPane(
- LStream * inStream)
- : LPane(inStream)
- {
- mIconRef = NULL;
- mUseIconID = true;
- mIconID = icon_UnknownFileTypeIcon;
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~FileIconPane Destructor [public]
- // ---------------------------------------------------------------------------
-
- FileIconPane::~FileIconPane()
- {
-
- }
-
- // ---------------------------------------------------------------------------
- // • SetIconRef [public]
- // ---------------------------------------------------------------------------
-
- void
- FileIconPane::SetIconRef(
- IconRef inIconRef)
- {
- mIconRef = inIconRef;
- mUseIconID = false;
-
- Refresh();
- }
-
-
- // ---------------------------------------------------------------------------
- // • SetIconID [public]
- // ---------------------------------------------------------------------------
-
- void
- FileIconPane::SetIconID(
- ResID inColorIconID)
- {
- mUseIconID = true;
- mIconID = inColorIconID;
-
- Refresh();
- }
-
-
- // ---------------------------------------------------------------------------
- // • DrawSelf [public]
- // ---------------------------------------------------------------------------
-
- void
- FileIconPane::DrawSelf()
- {
- Rect boundsRect;
- CalcLocalFrameRect(boundsRect);
-
- if (!mUseIconID)
- {
- if (mIconRef != NULL && ::IsValidIconRef(mIconRef))
- {
- // Plot the icon in the center
- OSErr err = ::PlotIconRef(
- &boundsRect,
- atAbsoluteCenter,
- IsEnabled() && IsActive() ? ttNone : ttDisabled,
- kIconServicesNormalUsageFlag,
- mIconRef);
- SignalIf_(err != noErr);
- }
- }
- else
- {
- CIconHandle iconHandle = ::GetCIcon(mIconID);
- SignalIf_(iconHandle == NULL);
-
- if (iconHandle != NULL)
- {
- // Plot a generic icon in the center
- OSErr err = ::PlotCIconHandle(
- &boundsRect,
- atAbsoluteCenter,
- IsEnabled() && IsActive() ? ttNone : ttDisabled,
- iconHandle);
- SignalIf_(err != noErr);
-
- ::DisposeCIcon(iconHandle);
- }
- }
- }
-
-
-